/**
 * CUBE消息处理工具
 * 可根据不同CUBE类型子类型执行对应函数
 */

import cubeData from "./cubeData";
import category from "../../config/cubeDataCategories";

export function dealData(msg){
    let recvMsg = new cubeData();
    let {type, subtype} = recvMsg.verifyMessage(msg);
    switch (type) {
        case category.TYPE[0]:
            if(subtype === "RECEIVE"){
                let ret = [];
                let i;
                for (i in recvMsg.cubeMsg.RECORD){
                    ret[i] = {
                        key : i,
                        option : recvMsg.cubeMsg.RECORD[i]
                    }
                    i++;
                }
                return ret;
            }
            break;
        case category.TYPE[1]:
            if(subtype === "STRING_DESC"){
                let ret = [];
                recvMsg.cubeMsg.RECORD.forEach((r) => {
                    ret.push({
                        string : r.string,
                        desc : r.desc
                    })
                })
                return ret;
            }
            break;

        default:
            console.log('不知道如何处理这条(%s %s)消息', type, subtype);
            break;
    }
}
